package com.nageoffer.shortlink.admin.test;

import java.util.HashMap;
import java.util.Map;

public class ifElseDemo {
    public static void main(String[] args) {
        //写法一
        String payType = "alipay";
        if ("alipay".equals(payType)) {
            System.out.println("支付宝支付成功");
        }else if ("wechatPay".equals(payType)) {
            System.out.println("微信支付成功");
        }
        //写法二
        Map<String,Runnable> map  = new HashMap<String,Runnable>();
        map.put("alipay",()-> System.out.println("支付宝支付成功"));
        map.put("wechatPay",()-> System.out.println("微信支付成功"));
        map.get("alipay").run();
        //写法三
        interface IPay{
            void pay();
        }
        class AliPay implements IPay{

            @Override
            public void pay() {
                System.out.println("支付宝支付成功");
            }
        }
        class WechatPay implements IPay{

            @Override
            public void pay() {
                System.out.println("微信支付成功");
            }
        }
        Map<String,IPay> map1 = new HashMap<>();
        map1.put("wechatPay",new WechatPay());
        map1.put("aliPay",new AliPay());
        map1.get(payType).pay();
        class payFactory{
            public static IPay getInstance(String payType){
                if (payType.equals("alipay")){
                    return new AliPay();
                }else if (payType.equals("wechatPay")){
                    return new WechatPay();
                }
                return null;
            }
        }
        Map<String,IPay> map2 = new HashMap<>();
        map1.put("wechatPay",payFactory.getInstance("wechatPay"));
        map1.put("aliPay",payFactory.getInstance("aliPay"));
        map1.get(payType).pay();

    }
}
